/**
    * Created by Choisaaaa on 2018/4/25.
 */

require("./payment.css");
require("page/common/nav/nav.js");
require("page/common/header/header.js");
var _payment = require("service/payment-service.js");
var _mm = require("util/mm.js");
var paymentTemplate = require("./payment.string");

var page = {
    data : {
      orderNumber :  _mm.getUrlParam("orderNumber")
    },
    init : function (){
        this.onLoad();
    },

    onLoad : function(){
        this.loadPaymentInfo();
    },
    loadPaymentInfo : function () {
        var _this = this;
        var $pageWrap = $(".page-wrap");
        _payment.getPaymentInfo(this.data.orderNumber,
            function (res) {
               var paymnetHtml =  _mm.renderHtml(paymentTemplate,res.data);
                $pageWrap.html(paymnetHtml);
                _this.listenOrderStatus();
            }, function (err) {
                _mm.errorTips();
            });
    },
    listenOrderStatus : function(){
        var _this = this;
        this.paymentTimer = window.setInterval(function(){
            _payment.getPaymentStatus(_this.data.orderNumber, function(res){
                if(res.data == true){
                    window.location.href
                        = './result.html?type=payment&orderNumber=' + _this.data.orderNumber;
                }
            });
        }, 5e3);
    }


};

$(function(){
    page.init();
});

